package com.cskaoyan.service;

import com.cskaoyan.bean.User;
import com.cskaoyan.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 类<code>Doc</code>用于：TODO
 *
 * @author Acher
 * @version 1.0
 * @date 2021-10-16
 */
@Service
public class UserServiceImpl implements UserService{

    @Autowired
    UserMapper userMapper;

    @Override
    public boolean login(User user) {
        return userMapper.insertUser(user);
    }

    @Override
    public List<User> getUsers() {
        List<User> userList = userMapper.selectAllUsers();
        if (userList == null)   userList = new ArrayList<>();
        return userList;
    }

    @Override
    public int deleteUser(Integer id) {
        return userMapper.deleteUser(id);
    }

    @Override
    public int getUserById(Integer id) {
        return userMapper.selectUserById(id);
    }

    @Override
    public int update(User user) {
        return userMapper.update(user);
    }

    @Override
    public Integer updateUserNameById(Integer id, String name) {
        return userMapper.updateUserNameById(id,name);
    }
}
